import { Injectable } from "@angular/core";

@Injectable({
  providedIn: 'root'
})
export class ProductService {
  products = [
    {
      id: '1',
      code: '1801',
      name: '角ハイボ-ル',
      onSale: true,
      quantity: 20,
      price: 3000,
    },
    {
      id: '2',
      code: '1802',
      name: 'コ-ラハイボ-ル',
      onSale: true,
      quantity: 60,
      price: 4999,
    },
    {
      id: '3',
      code: '1803',
      name: 'ジンジャ-ハイボ-ル',
      onSale: false,
      quantity: 20,
      price: 5999,
    },
    {
      id: '4',
      code: '1804',
      name: '生ビ-ル 中ジョッキ',
      onSale: true,
      quantity: 400,
      price: 380,
    },
    {
      id: '5',
      code: '1805',
      name: '生ビ-ル 大ジョッキ',
      onSale: true,
      quantity: 400,
      price: 580,
    },
    {
      id: '6',
      code: '1806',
      name: '瓶ビ-ル 中',
      onSale: true,
      quantity: 400,
      price: 500,
    },
    {
      id: '7',
      code: '1807',
      name: '青島ビ-ル',
      onSale: true,
      quantity: 220,
      price: 480,
    },
    {
      id: '8',
      code: '1808',
      name: 'アサヒ糖質0',
      onSale: true,
      quantity: 220,
      price: 350,
    },
    {
      id: '9',
      code: '1809',
      name: '響ボトル',
      onSale: true,
      quantity: 780,
      price: 2580,
    },
    {
      id: '10',
      code: '1810',
      name: '山崎ボトル',
      onSale: true,
      quantity: 900,
      price: 2680,
    },
    {
      id: '11',
      code: '1811',
      name: '醤油チャ-ハン',
      onSale: true,
      quantity: 100,
      price: 780,
    },
  ];

  public addGoods(id: string, code: string, name: string, onSale: boolean, quantity: number, price: number) {
    this.products.push({
      id: parseInt(this.products[this.products.length - 1].id) + 1 + "",
      code: code,
      name: name,
      onSale: onSale,
      quantity: quantity,
      price: price,
    });
  }

  public deleteGoods(id: string) {
    this.products = this.products.filter((item) => {
      return item.id != id
    })
    return this.products;
  }

}
